﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.Model;
using GtsServer.Common;
using GtsServer.Manage.Controller;

namespace GtsServer.Manage.IISPage.Ajax
{
    /// <summary>
    /// NoticeTypeAjax 的摘要说明
    /// </summary>
    public class NoticeTypeAjax : IHttpHandler
    {
        NoticeTypeController Controller = new NoticeTypeController();
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request["action"] != null)
            {
                string type = string.Empty;
                type = context.Request["action"];
                switch (type)
                {
                    case "GetList":
                        GetList(context);
                        break;
                    case "Add":
                        Add(context);
                        break;
                    case "Update":
                        Update(context);
                        break;
                    case "Delete":
                        Delete(context);
                        break;
                    default:
                        break;
                }
            }
        }

        private void GetList(HttpContext context)
        {
            List<NoticeType> list = Controller.GetList();
            string json = JsonHelper.ListToJson<NoticeType>(list);
            context.Response.Write(json);
        }
        private void Add(HttpContext context)
        {
            string name = context.Request["Name"];
            bool IsFullScreen =Convert.ToBoolean(context.Request["IsFullScreen"]);
            bool IsStick =Convert.ToBoolean(context.Request["IsStick"]);
            bool IsRoll =Convert.ToBoolean(context.Request["IsRoll"]);
            NoticeType model = new NoticeType()
            {
                Name=name,
                IsFullScreen=IsFullScreen,
                IsStick=IsStick,
                IsRoll=IsRoll

            };
            int id = Controller.Add(model);
            context.Response.Write(id);
        }
        private void Update(HttpContext context)
        {
            string name = context.Request["Name"];
            bool IsFullScreen = Convert.ToBoolean(context.Request["IsFullScreen"]);
            bool IsStick = Convert.ToBoolean(context.Request["IsStick"]);
            bool IsRoll = Convert.ToBoolean(context.Request["IsRoll"]);
            int ID = Convert.ToInt32(context.Request["id"]);
            NoticeType model = new NoticeType()
            {
                ID=ID,
                Name=name,
                IsFullScreen=IsFullScreen,
                IsStick=IsStick,
                IsRoll=IsRoll
            };
            context.Response.Write(Controller.Update(model));
        }
        private void Delete(HttpContext context)
        {
            int id = Int32.Parse(context.Request["id"]);
            context.Response.Write(Controller.Delete(id));
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}